//
//  ACAudienceForbidenController.m
//  ACLiteAVUISDK
//
//  Created by 冯琰琰 on 2021/4/1.
//

#import "ACAudienceForbidenController.h"
#import "ACLiveMemberListCell.h"

@interface ACAudienceForbidenController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableview;
@property(nonatomic,strong)NSArray<TRTCLiveUserInfo *> *userList;
@end

@implementation ACAudienceForbidenController

-(UITableView *)tableview{
    if (!_tableview) {
        _tableview = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.estimatedRowHeight = 68;
        NSBundle *curB = [NSBundle BundleWithBundleName:ACLiteAVUISDK targetClass:[self class] ];
        [_tableview registerNib:[UINib nibWithNibName:@"ACLiveMemberListCell" bundle:curB] forCellReuseIdentifier:@"ACLiveMemberListCell"];
        _tableview.tableFooterView = [UIView new];
    }
    return _tableview;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.tableview];
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-ACSafeAreaBottomHeight);
        make.top.mas_equalTo(0);
    }];
}
-(void)setLiveRoom:(TRTCLiveRoom *)liveRoom{
    _liveRoom = liveRoom;
    @weakify(self);
    [_liveRoom getAudienceList:^(int code, NSString * _Nullable message, NSArray<TRTCLiveUserInfo *> * _Nonnull userList) {
        @strongify(self)
        self.userList = userList;
        [self.tableview reloadData];
    }];
}
#pragma mark - UITableViewDelegate,UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.userList.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ACLiveMemberListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ACLiveMemberListCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[ACLiveMemberListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ACLiveMemberListCell"];
    }
    [cell.cancelForbiden setTitle:@"禁言" forState:UIControlStateNormal];
    [cell.cancelForbiden setHidden:NO];
    TRTCLiveUserInfo *liveUserInfo = self.userList[indexPath.row];
    cell.userInfo = liveUserInfo;
    @weakify(self)
    cell.clickActionHandler = ^(NSInteger value) {
        @strongify(self)
        if (![liveUserInfo.userId isEqualToString:[[ACUserProfileManager shareInstance] userModel].user_id]) {
            [self.liveRoom setGroupMemberMuteWithTime:0 userID:liveUserInfo.userId callback:^(int code, NSString * _Nullable message) {
                DDLogInfo(@"setGroupMemberMuteWithTime------%d------%@",code,message);
            }];
            [SVProgressHUD showInfoWithStatus:@"用户15313758530被主持人解除了禁言"];
        }else{
            [SVProgressHUD showErrorWithStatus:@"不能对自己禁言"];
        }
    };
    return  cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

#pragma mark - JXCategoryListContentViewDelegate

/**
 实现 <JXCategoryListContentViewDelegate> 协议方法，返回该视图控制器所拥有的「视图」
 */
- (UIView *)listView {
    return self.view;
}

@end
